package br.com.igrejacristavida.adapter;

import java.util.List;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import br.com.igrejacristavida.activity.R;
import br.com.igrejacristavida.model.Pregacao;

public class PregacaoAdapter extends ArrayAdapter<Pregacao> {

	private int resource;

	public PregacaoAdapter(Context context, List<Pregacao> items) {
		super(context, R.layout.pregacao_item, items);
		resource = R.layout.pregacao_item;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		RelativeLayout itemView;

		if (view == null) {
			itemView = new RelativeLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi;
			vi = (LayoutInflater) getContext().getSystemService(inflater);
			vi.inflate(resource, itemView, true);
		} else {
			itemView = (RelativeLayout) view;
		}

		Pregacao pregacao = getItem(position);
		
		ImageView imageView = (ImageView) itemView.findViewById(R.id.pregacao_icon);
		imageView.setImageURI(Uri.parse("http://igrejacristavida.com.br/root-site/wp-content/uploads/2013/12/Advento-170-X-170-150x150.png"));
		
		TextView nomeText = (TextView) itemView.findViewById(R.id.pregacao_title);
		nomeText.setText(pregacao.getNome());

		TextView pregadorText = (TextView) itemView.findViewById(R.id.pregacao_author);
		pregadorText.setText(pregacao.getPregador());

		return itemView;
	}
}
